package com.aaa.jvmtest.dui;

import java.util.ArrayList;
import java.util.List;

/**
 * 堆内存溢出 使用-Xmx8m指定大小
 *
 * @author Tu
 * @date 2022/5/12 16:22
 */
public class DuiOutOfMemoryError {

    public static void main(String[] args) {
        int i = 0;
        try {
            List<String> strList = new ArrayList<>(10);
            String str = "hello";
            while (true) {
                strList.add(str);
                str = str + str;
                i++;
            }
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println(i);
        }
    }

}
